<?php

include_once 'cos_api.php';
include_once 'db_api.php';

$cos = new cos ;
$db = new db;
if($_POST['bucket']){
    switch ($_POST['bucket']){
        case 'zm':
            $cos -> setBucket('top237-1306391227');
            $cos -> setRegion('ap-beijing');
            break;
        case 'hy':
            $cos -> setBucket('huayu-1306391227');
            $cos -> setRegion('ap-nanjing');
            break;
    }

}


if($_POST['type']){

    switch($_POST['type']){
        case 'cos/add':
            $cos -> uploadFile();
            break;
        case 'cos/del':
            $cos ->delFile();
            break;
        case 'cos/down':
            $cos ->downFile();
            break;
        case 'cos/getUrl':
            $cos->getFileUrl();
            break;
        case 'hy/getList':
            verfiyParmas('infoType');
            $db->getHyList($_POST['infoType']);
            break;
        case 'hy/gitItem':
            verfiyParmas('id');
            $db->getHyitem($_POST['id']);
            break;
        case 'zm/getList':
            $db->getZmList();
            break;
        case 'zm/gitItem':
            verfiyParmas('id');
            $db->getZmItem($_POST['id']);
            break;
        default:
            $res = Array(
                'code'=>0,
                'msg'=>'请求参数 type 未识别到'
            );
            echo json_encode($res);
            break;
    }

}else{
    $res = Array(
        'code'=>0,
        'msg'=>'请求参数 type 未识别到'
    );
    echo json_encode($res);
};
//校验post参数传递
function verfiyParmas($paramsKey){

    if(!$_POST[$paramsKey]){
        $res = Array(
            'code'=>0,
            'msg'=>$paramsKey . "这个key值没有找到"
        );
        die(json_encode($res));
    }
}

//$db = new db;

//$db->getZmList();
//$db->getZmItem('5b00f970605d87b30340f35540469ebf');

//$db->getHyList('主日信息');
//$db->getHyitem('20210606ZR');

